<?php
require_once 'common.php';
require_once 'Student.php';
require_once 'ResultData.php';


if (isGet()) {
    echo "不得以GET访问";
    exit;
}

$id = trim($_REQUEST['id']);
$name = trim($_REQUEST['name']);
$sex = trim($_REQUEST['sex']);
$age = trim($_REQUEST['age']);
$edu = trim($_REQUEST['edu']);
$city = trim($_REQUEST['city']);
$no = trim($_REQUEST['no']);

$result = new ResultData();
if ($id == "") {
    $result->code = 404;
    $result->msg = "id不能为空";
    exit(json_encode($result));
}


$json_string = file_get_contents('data.json');
// 用参数true把JSON字符串强制转成PHP数组
$data = json_decode($json_string);
$id = intval($id);
$index = -1;
foreach ($data as $key => $value) {
    if ($value->id == $id) {
        $index = $key;
    }
}
if ($index >= 0) {
    unset($data[$index]);
}

$json_string = json_encode(array_values($data));

file_put_contents('data.json', $json_string);

exit(json_encode($result));
